<template>
  <div class="header-user">
    <div class="user">
      <div class="avatar" @click="onClickUser">
        <van-image :src="formatAvatar(user.name)" fit="cover" round />
      </div>
      <div class="box">
        <div class="name">{{ user.name }}</div>
        <div class="time">{{ formatTime(props.time) }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { formatTime } from '../utils/format-time'
import { userDetail } from '../service/user/types'
import { formatAvatar } from '../utils/format-avatar'

const props = defineProps<{
  time: Date | string
  user: userDetail.User
}>()
const router = useRouter()

const onClickUser = () => {
  router.push(`/publish/${props.user.id}`)
}
</script>

<style lang="scss" scoped>
.header-user {
  .user {
    padding: 15px 0;
    display: flex;
    height: 30px;
    align-items: center;
    .avatar {
      .van-image {
        height: 30px;
        width: 30px;
      }
    }
    .box {
      margin-left: 20px;
      .name {
        font-weight: 540;
      }
      .time {
        font-size: 12px;
        color: #ccc;
      }
    }
  }
}
</style>
